$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/busershield/getList',
        datatype: "json",
        colModel: [
            { label: '用户编号', name: 'userId', index: 'user_id',align: "center", width: 50,},
            { label: '用户昵称', name: 'userName', index: 'user_name', align: "center", width: 80},
            { label: '公众号', name: 'gzhName', index: 'gzh_name',align: "center", width:60 },
            { label: '屏蔽时间', name: 'createTime', index: 'create_time',align: "center", width: 80 },
            { label: '操作', name: '', index: '',align: "center", width: 80 ,formatter:function(value,options,rowData){
                    var userId=rowData["userId"];
                    return "<a class='btn btn-danger' onclick='vm.delete("+userId+")'>删除</a>";
                }
            },
        ],
        viewrecords: true,
        height: "100%",
        rowNum: 15,
        rowList : [15,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        postData:{'userId': vm.q.userId,'userName': vm.q.userName,"gzhCode": vm.q.gzhCode},
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });

    $.ajax({
        type: "POST",
        async:false,
        url: baseURL + 'sys/buserinfo/getUserGzhList',
        contentType: "application/json",
        success: function(r){
            if(r.code==0){
                $("#selectUserGzhList").append(
                    "<option value=''>全部平台</option>");
                for(var i=0;i<r.userGzhList.length;i++){
                    $("#selectUserGzhList").append(
                        "<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
                }
            }
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            userId: null,
            userName: null,
            gzhCode: "",
        },
        showList: true,
    },
    methods: {
        query: function () {
            vm.reload(1);
        },
        delete: function (userId) {
            if (!userId) {
                alert("用户不存在");
                return;
            }

            layer.confirm("您确定删除吗？", function (index) {
                $.ajax({
                    type: "POST",
                    url: baseURL + 'sys/busershield/deleteByUserId/' + userId,
                    contentType: "application/json",
                    success: function(r){
                        if(r.code==0){
                            layer.close(index);
                            vm.reload(1);
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        reload: function (page) {
            debugger;
            vm.showList = true;
            if (!page) {
                page = $("#jqGrid").jqGrid('getGridParam','page');
            }
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'userId': vm.q.userId,'userName': vm.q.userName,"gzhCode": vm.q.gzhCode},
                page:page
            }).trigger("reloadGrid");
        },
    }
});